Centos修改swap虚拟内存大小方法 |
您所在的位置:网站首页 › linux 修改swap分区 › Centos修改swap虚拟内存大小方法 |
Centos修改swap虚拟内存大小方法 修改swap的全部步骤: [root@gamedb ~]# free –m[root@gamedb tmp]# dd if=/dev/zero of=/tmp/big_swap bs=1024 count=2000000[root@gamedb tmp]# du -sh /tmp/big_swap[root@gamedb tmp]# mkswap /tmp/big_swap[root@gamedb tmp]# swapon /tmp/big_swap[root@gamedb tmp]# free –m[root@gamedb tmp]# vi /etc/fstab# LABEL=SWAP-hda2 swap swap defaults 0 0 /tmp/big_swap swap swap defaults 0 0[root@gamedb ~]# free –m[root@gamedb tmp]# dd if=/dev/zero of=/tmp/big_swap bs=1024 count=2000000[root@gamedb tmp]# du -sh /tmp/big_swap[root@gamedb tmp]# mkswap /tmp/big_swap[root@gamedb tmp]# swapon /tmp/big_swap[root@gamedb tmp]# free –m[root@gamedb tmp]# vi /etc/fstab# LABEL=SWAP-hda2 swap swap defaults 0 0 /tmp/big_swap swap swap defaults 0 0 1、查看内存和swap大小,发现swap是内存大小的一半 [root@localhost tmp]# free -m total used free shared buffers cachedMem: 772 91 681 0 6 30-/+ buffers/cache: 53 718Swap: 1567 0 1567[root@localhost tmp]# free -m total used free shared buffers cachedMem: 772 91 681 0 6 30-/+ buffers/cache: 53 718Swap: 1567 0 1567 2、决定修改swap大小,首先在空间合适处创建用于分区的swap文件: [root@localhost tmp]# dd if=/dev/zero of=/tmp/big_swap bs=1024 count=2000000 记录了2000000+0 的读入记录了2000000+0 的写出2048000000字节(2.0 GB)已复制,69.5342 秒,29.5 MB/秒(注意:if 表示 infile,of 表示outfile,bs=1024 表示写入的每个块的大小为1024B=1KB(1024B字节=1024*8bit位)[root@localhost tmp]# dd if=/dev/zero of=/tmp/big_swap bs=1024 count=2000000 记录了2000000+0 的读入记录了2000000+0 的写出2048000000字节(2.0 GB)已复制,69.5342 秒,29.5 MB/秒(注意:if 表示 infile,of 表示outfile,bs=1024 表示写入的每个块的大小为1024B=1KB(1024B字节=1024*8bit位) 3、查看创建的文件大小是否符合要求: [root@localhost tmp]# du -sh big_swap 2.0G big_swap[root@localhost tmp]# ls -al big_swap-rw-r--r-- 1 root root 2048000000 12月 1 14:25 big_swap[root@localhost tmp]# du -sh big_swap 2.0G big_swap[root@localhost tmp]# ls -al big_swap-rw-r--r-- 1 root root 2048000000 12月 1 14:25 big_swap 4、将目的文件设置为swap分区文件: [root@localhost tmp]# mkswap big_swap mkswap: big_swap: warning: don't erase bootbits sectors on whole disk. Use -f to force.Setting up swapspace version 1, size = 1999996 KiBno label, UUID=25c3eaf2-43f9-487b-87b7-f76a712f5376[root@localhost tmp]# mkswap big_swap mkswap: big_swap: warning: don't erase bootbits sectors on whole disk. Use -f to force.Setting up swapspace version 1, size = 1999996 KiBno label, UUID=25c3eaf2-43f9-487b-87b7-f76a712f5376 5、激活swap,立即启用交换分区文件: [root@localhost tmp]# swapon big_swap[root@localhost tmp]# swapon big_swap 6、再次查看内存和虚拟内存,发现已经被正常修改: [root@localhost tmp]# free -m total used free shared buffers cachedMem: 772 705 66 0 2 627-/+ buffers/cache: 75 697Swap: 3521 0 3521[root@localhost tmp]# free -m total used free shared buffers cachedMem: 772 705 66 0 2 627-/+ buffers/cache: 75 697Swap: 3521 0 3521 7、若要想使开机时自启用,则需修改文件/etc/fstab中的swap行: [root@gamedb tmp]# vi /etc/fstab# LABEL=SWAP-hda2 swap swap defaults 0 0 /tmp/big_swap swap swap defaults 0 0[root@gamedb tmp]# vi /etc/fstab# LABEL=SWAP-hda2 swap swap defaults 0 0 /tmp/big_swap swap swap defaults 0 0 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |